//
//  productDetailsViewController.m
//  giuseppe
//
//  Created by Apple on 15/8/14.
//  Copyright (c) 2015年 GiantUmbrella. All rights reserved.
//

#import "productDetailsViewController.h"
#import "define.h"

@interface productDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>{
    
    UIView *detailView;
    UITableView *commentTableView;
}

@end

@implementation productDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.toolbarHidden = NO;
    
    //自定义的导航栏
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    navView.backgroundColor = [UIColor whiteColor];
    navView.alpha = 0.90;
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(10, 33, 27, 16);
    [backButton setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth/2-50, 20, 100, 40)];
    titleLabel.text = @"商品详情";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    [self initView];
    [self initToolBarView];
    [navView addSubview:backButton];
    [navView addSubview:titleLabel];
    [self.view addSubview:navView];

}

- (void)initView{
    
    
    UIScrollView *backScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    backScrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight*3);
    backScrollView.backgroundColor = [UIColor whiteColor];
    
    //大图展示
    UIImageView *goodsImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, 300)];
    goodsImage.image = [UIImage imageNamed:@"female"];
    
    [backScrollView addSubview:goodsImage];
    
    //商品介绍
    UIView *introductionView = [[UIView alloc]initWithFrame:CGRectMake(0, goodsImage.frame.origin.y+goodsImage.frame.size.height, kScreenWidth, 60)];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth-100, 30)];
    nameLabel.text = @"乔治白中学生校服班服";
    [introductionView addSubview:nameLabel];
    
    UILabel *priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, 80, 30)];
    priceLabel.text = @"998";
    priceLabel.textColor = mainColor;
    [introductionView addSubview:priceLabel];
    
    UILabel *soldLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, 30, 80, 30)];
    soldLabel.text = @"998";
    soldLabel.textColor = mainColor;
    [introductionView addSubview:soldLabel];
    
    UIButton *favoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    favoriteButton.frame = CGRectMake(kScreenWidth-100+30, 10, 50, 50);
    favoriteButton.backgroundColor = mainColor;
    [introductionView addSubview:favoriteButton];
    
    [backScrollView addSubview:introductionView];
    
    
    //尺码选择
    UIView *selectSizeView = [[UIView alloc]initWithFrame:CGRectMake(0, introductionView.frame.origin.y+introductionView.frame.size.height, kScreenWidth, 40)];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
    titleLabel.text = @"选择尺码";
    [selectSizeView addSubview:titleLabel];
    
    [backScrollView addSubview:selectSizeView];
    
    
    //其他商品
    UIView *otherGoodsImageListView = [[UIView alloc]initWithFrame:CGRectMake(0, selectSizeView.frame.origin.y+selectSizeView.frame.size.height, kScreenWidth, 120)];
    
    
    for (int i = 0; i <= 3; i++) {
        UIButton *otherGoodsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        otherGoodsButton.frame = CGRectMake(i*(kScreenWidth/3), 0, kScreenWidth/3, 100);
        [otherGoodsButton setImage:[UIImage imageNamed:@"male"] forState:UIControlStateNormal];
        otherGoodsButton.tag = 100 + i;
        [otherGoodsImageListView addSubview:otherGoodsButton];
        
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(i*(kScreenWidth/3), 100, kScreenWidth/3, 20)];
        nameLabel.text = @"乔治白白治乔";
        nameLabel.textAlignment = NSTextAlignmentCenter;
        [otherGoodsImageListView addSubview:nameLabel];
    
    }
    
    [backScrollView addSubview:otherGoodsImageListView];
    
    //选择按钮
    UIView *selectButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, otherGoodsImageListView.frame.origin.y+otherGoodsImageListView.frame.size.height, kScreenWidth, 30)];
    
    UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [detailButton setTitle:@"商品详情" forState:UIControlStateNormal];
    detailButton.backgroundColor = baseColor;
    detailButton.frame = CGRectMake(0, 0, kScreenWidth/2, 30);
    UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [commentButton setTitle:@"商品评论" forState:UIControlStateNormal];
    commentButton.backgroundColor = baseColor;
    commentButton.frame = CGRectMake(kScreenWidth/2, 0, kScreenWidth/2, 30);
    
    [selectButtonView addSubview:detailButton];
    [selectButtonView addSubview:commentButton];
    
    [backScrollView addSubview:selectButtonView];
    
    
    //商品详情
    detailView = [[UIView alloc]initWithFrame:CGRectMake(0, selectButtonView.frame.origin.y+selectButtonView.frame.size.height, kScreenWidth, 100)];
    UIImageView *detailImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, kScreenWidth-20, 100)];
    detailView.backgroundColor = mainColor;
    
    [detailView addSubview:detailImage];
    
    [backScrollView addSubview:detailView];
    
    //商品评论
    commentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, selectButtonView.frame.origin.y+selectButtonView.frame.size.height, kScreenWidth, kScreenHeight)];
    commentTableView.delegate = self;
    commentTableView.dataSource = self;
    
    [backScrollView addSubview:commentTableView];
    
    
    
    
    //添加整体
    [self.view addSubview:backScrollView];
    
    
}


- (void)initToolBarView{
    
    
    UIView *toolBarBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, self.navigationController.toolbar.frame.size.height)];
    toolBarBackView.backgroundColor = baseColor;
    
    
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.frame = CGRectMake(kScreenWidth-180, 0, 100, self.navigationController.toolbar.frame.size.height);
    [addButton setTitle:@"加入购物车" forState:UIControlStateNormal];
    addButton.backgroundColor = mainColor;
    addButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    
    
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeCustom];
    payButton.frame = CGRectMake(kScreenWidth-80, 0, 80, self.navigationController.toolbar.frame.size.height);
    [payButton setTitle:@"立即购买" forState:UIControlStateNormal];
    payButton.backgroundColor = mainColor;
    payButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    
    [toolBarBackView addSubview:addButton];
    [toolBarBackView addSubview:payButton];
    
    [self.navigationController.toolbar addSubview:toolBarBackView];
    
    
    
}



#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 5;
    
    
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 130;
    
}


#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *NOTIFY = @"cellSetOutVC";
    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
        
      
        UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
        
        UILabel *userLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 20, 60, 20)];
        
        UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-100, 20, 100, 20)];
        dateLabel.textColor = [UIColor lightGrayColor];
        
        UILabel *contentsLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 50, kScreenWidth-60, 50)];
        
        
        [cell.contentView addSubview:userImage];
        [cell.contentView addSubview:userLabel];
        [cell.contentView addSubview:dateLabel];
        [cell.contentView addSubview:contentsLabel];
        
        
        
        
    }
    


    return cell;
    
    
    
}
#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}
#pragma mark--- tableViewDelegat 点击方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    
    
}





- (void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
